package leetcode;

public class Leetcode718 {
    public int findLength(int[] A, int[] B) {
        int n1 = A.length;
        int n2 = B.length;
        int[][] dp = new int[n1+1][n2+1];
        int max = 0;
        for (int i = 1; i <= n1; i++) {
            for (int j = 1; j <= n2; j++) {
                if(A[i-1] == B[j-1]){
                    dp[i][j] = dp[i-1][j-1];
                }
                max = Math.max(dp[i][j],max);
            }
        }
        return max;
    }
}
